url = "/time-sale.html"
layout = "default"
description = "time-sale"
is_hidden = 0
==
use Carbon\Carbon;
use Jason\Ccshop\Models\Promotion;
use Jason\Ccshop\Components\Catalog;
use Jason\Ccshop\Plugin;
function onstart(){
      $this['now'] = "christmas_now";
      $this['next'] = "christmas_next";
      $promotion = Promotion::where('name', $this['now'])->first();
      if(!$promotion || strtotime($promotion->to_date) < time())
        return redirect('/404.html');
      $now = Carbon::now();
      if( $now = $promotion->from_date or $now = $promotion->to_date){
          Cache::tags('promotions')->flush();
      }
      $promotionNext = Promotion::where('name', $this['next'])->first();
      
      if($promotion){

      $promotion->from_date = strtotime($promotion->from_date);
      $promotion->to_date = strtotime($promotion->to_date);
      $promotion->now_date = time();
      $this['promotion'] = $promotion;

      }
      if($promotionNext){
      $promotionNext->from_date = strtotime($promotionNext->from_date);
      $promotionNext->to_date = strtotime($promotionNext->to_date);
      $promotionNext->now_date = time();
      $this['promotionNext'] = $promotionNext;
    }
}
==
{% put page_title %}タイムセール{% endput %}
{% put meta_keywords %}タイムセール，期間限定セール，期間限定タイムセール、ビッグセール，インターネット通販，割引{% endput %}
{% put meta_description %}fancy-styleのタイムセール。期間限定のタイムセールを実施中！数量＆期間限定のタイムセールを実施中！毎週更新 セール商品盛りだくさん、人気商品がお買い得価格で続々登場 。この機会をぜひお見逃しなく！{% endput %}
<link rel="stylesheet" type="text/css" href="{{ 'assets/css/time-sale.css'|theme }}"/>
{% put scripts %}
<script type="text/javascript" src="{{ 'assets/js/time-sale.js'|theme }}"></script>
{% endput %}
<div class="content">
  <div class="banner">
    {% for item in catalog.fetchAd('m-time-sale').items %}
    <a href="{{ item.link }}">
      <img src="{{ item.image.getPath() }}" alt="{{ item.name }}">
    </a>
   {% endfor %}
  </div>
  <ul class="time-sale-ul">
    <li class="active">実施中</li>
    <li>企画中</li>
  </ul>
  <div class="time-sale-box">
    <div class="time-sale-cont" style="display:block;">
      <div class="topDate">
        <span>残り時間：</span>
        <div id="date-1"></div>
      </div>
      <div id="promotionNow" style="display: none">
        {% if promotion %}
        <h4 class="starttime">{{ promotion.from_date |date("Y/m/d H:i:s")  }}</h4>
        <h4 class="endtime">{{ promotion.to_date |date("Y/m/d H:i:s")  }}</h4>
        <h4 class="nowtime">{{ promotion.now_date |date("Y/m/d H:i:s")  }}</h4>
        {% endif %}  
      </div>
      <ul class="ulFour">
      {% for key, val in catalog.getProductsByPromotionName(now) %}
        {% set salenum = getSaleOrderNum(val.id) %}
        {% set presale = getProductPresale(val.id) %}
        {% set widthnum = salenum * 100 // presale %}
        {% set leftnum = 34 + (salenum * 100 / presale) / 2 %}
        <li class="time-sale-item">
            <a href="{{ val.url }}?rel=popular">
              {% if salenum != 0%}
              {% else %}
              <div class="sell-out">タイムセール終了<br>通常価格に戻りました</div>
              {% endif %}
                <img src="{{ val.f_thumb }}" alt="{{ val.name }}">
                <h3>{{ val.name }}</h3>
                <p><span class="ordPrice">{{ val.list_price|displayPrice }} 税込</span>{% if val.discount %}({{ val.discount }} OFF){% endif %}</p>
                <p><span class="price">{{ val.id|getDbPrice|displayPrice }} 税込</span></p>
                <h4 class="limit">
                  <strong>数量限定：{{ presale }}</strong>
                  <p><i class="widthdata" style="width:{{ widthnum }}%;"></i></p>
                  <span style="left:{{ leftnum }}%">{{ salenum }}点</span>
                </h4>
<!--                 {% set dataInfo = getProductPromotionFromToDate(val.id) %}
                <h4 class="starttime">{{ dataInfo.from |date("Y/m/d H:i:s")  }}</h4>
                <h4 class="endtime">{{ dataInfo.to |date("Y/m/d H:i:s")  }}</h4>
                <h4 class="nowtime">{{ dataInfo.now |date("Y/m/d H:i:s")  }}</h4> -->
            </a>
            {% if salenum != 0%}
            <a href="{{ val.url }}" type="button" class="btn-time-sale">今すぐ購入</a>
            {% else %}
            <button  disabled class="btn-time-sale btn-disable">タイムセール終了</button>
            {% endif %}
        </li>
      {% endfor %}
      </ul>
    </div>
    <div class="time-sale-cont">
    	<div class="topDate">
        <span>開始時間：</span>
        <div id="date-2"></div>
      </div>
      <div id="promotionNext" style="display: none">
        {% if promotion %}
        <h4 class="starttime">{{ promotion.from_date |date("Y/m/d H:i:s")  }}</h4>
        <h4 class="endtime">{{ promotion.to_date |date("Y/m/d H:i:s")  }}</h4>
        <h4 class="nowtime">{{ promotion.now_date |date("Y/m/d H:i:s")  }}</h4>
        {% endif %}  
      </div>
      <ul class="ulFour">
      {% for key, val in catalog.getProductsByPromotionName(next) %}
        {% set salenum = getSaleOrderNum(val.id) %}
        {% set presale = getProductPresale(val.id) %}
        <li class="time-sale-item">
            <a href="{{ val.url }}?rel=popular">
                <img src="{{ val.f_thumb }}" alt="{{ val.name }}">
                <h3>{{ val.name }}</h3>
                <p><span class="ordPrice">{{ val.list_price|displayPrice }} 税込</span>{% if val.discount %}({{ val.discount }} OFF){% endif %}</p>
                <p><span class="price">{{ val.id|getDbPrice|displayPrice }} 税込</span></p>
                <h4 class="limitTwo">
                  <strong>数量限定：{{ presale }}</strong>
                  <p><i class="widthdata" style="width:100%;"></i></p>
                  <span style="left:84%">100%</span>
                </h4>
            </a>
            <a href="{{ val.url }}" type="button" class="btn-time-sale btn-disable">今すぐ購入</a>
        </li>
      {% endfor %}
      </ul>
    </div>
  </div>
</div>